package com.patrol.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.patrol.pojo.TaskPoint;
import com.patrol.pojo.UserTask;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TaskPointDao extends BaseMapper<TaskPoint>{

    @Select("select * from task_point where task_name=#{taskName}")
    TaskPoint selectPointByName(String taskName);

    @Insert("insert into user_task (task_id,user_id,sign) values(#{point},#{user},0)")
    void allotPoint(int user, int point);

    @Select("select task_id from user_task WHERE user_id=#{userId} and sign=0")
    List<Integer> findPointIds(int userId);

    @Update("update user_task set task_state=0,create_time=#{date} where task_id=#{taskId}")
    int changePointState(int taskId, String date);

    @Update("update user_task set task_state=1,finish_time=#{date} where task_id=#{taskId} and user_id=#{userId}")
    int finishPoint(int taskId, int userId, String date);

    @Delete("delete from user_task where user_id=#{userId} and task_id=#{taskId}")
    int delUserTask(int userId, int taskId);

    @Select("select task_state from user_task where task_id=#{taskId} and user_id=#{userId} and sign=0")
    int selectTaskState(int taskId, int userId);

    @Select("select id from user_task where user_id=#{userId} and task_id=#{taskId} and sign=0")
    Integer selectUserPoint(int userId, int taskId);

    @Select("select realName from user where userId in (select user_id from user_task where task_id=#{taskId})")
    List<String> selectUUPoint(int taskId);

    @Select("select task_state from user_task where task_id=#{taskId} and user_id=#{userId} and sign=0")
    int selectRWPointState(Integer userId, Integer taskId);

    @Update("update user_task set sign=1 where user_id=#{userId}")
    void updatePointSign(String userId);
}